package tgc.edu.examxy.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import tgc.edu.examxy.custom.CommonService;
import tgc.edu.examxy.entity.Student;
import tgc.edu.examxy.entity.TbClass;
import tgc.edu.examxy.repository.StudentRepository;

@Service
public class StudentService extends CommonService<Student, UUID>{
	@Autowired
	private StudentRepository studentdao;
	
	public void saves(Student studententity) {
		studentdao.save(studententity);
	}

	public Student findByUsername(String idcode) {
		return studentdao.findByUsername(idcode);
	}

	public List<Student> findByTbClass(TbClass tbClass) {
		return studentdao.findByTbClass(tbClass);
	}

	public Student findByOpenid(String openid) {
		return studentdao.findByOpenid(openid);
	}


	public Student findByTypeAndUsername(String string, String username) {
		return studentdao.findByTypeAndUsername(string,username);
	}

	public Student findByOpenid(String openid, String string) {
		return studentdao.findByOpenidAndType(openid,string);
	}

	public Student findByTypeAndOpenid(String string, String openid) {
		return studentdao.findByTypeAndOpenid(string,openid);
	}

	public List<Student> findByTbClassAndTypeAndIsUsed(TbClass tbClass, String string, boolean b) {
		return studentdao.findByTbClassAndTypeAndIsUsed(tbClass,string,b);
	}

	public String maxStudent(TbClass tbclassEntity) {
		String manStudent = studentdao.manStudent(tbclassEntity.getId());
		if(manStudent.length()<3) {
			String ling ="";
			for (int i = manStudent.length(); i < 3; i++) {
				ling = "0"+ling;
			}
			manStudent = ling + manStudent;
		}
		return manStudent;
	}


}
